//
//  CompanyTopTableViewCell.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/8/24.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "CompanyTopTableViewCell.h"

@interface CompanyTopTableViewCell()
{
    UIImageView * avatar;
    UIImageView * vip;
    UILabel * titleLabel;
    UILabel * rateLabel;
    UILabel * typeLabel;
    UILabel * descriptionLabel;
    UIButton * button1;
    UIButton * button2;
    UIButton * button3;
    UIView * line;
}
@end

@implementation CompanyTopTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        avatar = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
        avatar.contentMode = UIViewContentModeScaleAspectFill;
        avatar.clipsToBounds = YES;
        [self addSubview:avatar];
        
        vip = [[UIImageView alloc]initWithFrame:CGRectMake(40, 40, 15, 15)];
        [self addSubview:vip];
        
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, ScreenWidth, 20)];
        titleLabel.font = [UIFont boldSystemFontOfSize:15];
        [self addSubview:titleLabel];
        
        rateLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 30, ScreenWidth, 20)];
        rateLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:rateLabel];
        
        typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 50, ScreenWidth, 20)];
        typeLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:typeLabel];
        
        descriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 75, ScreenWidth - 70, 20)];
        descriptionLabel.font = [UIFont systemFontOfSize:13];
        descriptionLabel.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
        descriptionLabel.numberOfLines = 0;
        [self addSubview:descriptionLabel];
        
        button1 = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 80, 10, 70, 20)];
        button1.titleLabel.font = [UIFont systemFontOfSize:13];
        button1.layer.cornerRadius = 10;
        [button1 setTitle:@"成长历程" forState:UIControlStateNormal];
        button1.backgroundColor = themeColor;
        [button1 addTarget:self action:@selector(button1Action) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button1];
        
        button2 = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 120, 40, 110, 20)];
        button2.titleLabel.font = [UIFont systemFontOfSize:13];
        button2.layer.cornerRadius = 10;
        [button2 setTitle:@"加入" forState:UIControlStateNormal];
        button2.backgroundColor = themeColor;
        [button2 addTarget:self action:@selector(button2Action) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button2];
        
        line = [[UIView alloc]initWithFrame:CGRectMake(0, 105, ScreenWidth, 10)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self addSubview:line];
    }
    return self;
}

+(CGFloat)heightWithData:(NSDictionary *)data
{
    if ([[data allKeys]count])
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - 70, 20)];
        label.font = [UIFont systemFontOfSize:13];
        label.numberOfLines = 0;
        label.text = [data objectForKey:@"Intro"];
        [label sizeToFit];
        if (label.frame.size.height < 20)
        {
            return 20 + 75 + 10 + 10;
        }
        else
        {
            return label.frame.size.height + 75 + 10 + 10;
        }
    }
    else
    {
        return 135;
    }
}

-(void)loadData:(NSDictionary *)data
{
    [avatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://pic.xrsquare.com/%@",[data objectForKey:@"HeadPic"]]]];
    [vip sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[data objectForKey:@""]]]];
    
    titleLabel.text = [data objectForKey:@"NickName"];
    rateLabel.text = [NSString stringWithFormat:@"好评率:%@%%",[data objectForKey:@"Evaluate"]];
    typeLabel.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Web_Company_Property"]];
    
    if ([typeLabel.text isEqualToString:@"0"]) {
        typeLabel.text = @"国有企业";
    }
    if ([typeLabel.text isEqualToString:@"1"]) {
        typeLabel.text = @"集体企业";
    }
    if ([typeLabel.text isEqualToString:@"2"]) {
        typeLabel.text = @"有限责任公司";
    }
    if ([typeLabel.text isEqualToString:@"3"]) {
        typeLabel.text = @"股份有限公司";
    }
    if ([typeLabel.text isEqualToString:@"4"]) {
        typeLabel.text = @"私营企业";
    }
    if ([typeLabel.text isEqualToString:@"5"]) {
        typeLabel.text = @"中外合资企业";
    }
    if ([typeLabel.text isEqualToString:@"6"]) {
        typeLabel.text = @"外商投资企业";
    }
    if ([typeLabel.text isEqualToString:@"7"]) {
        typeLabel.text = @"事业单位";
    }
    if ([typeLabel.text isEqualToString:@"8"]) {
        typeLabel.text = @"国家机关";
    }
    if ([typeLabel.text isEqualToString:@"9"]) {
        typeLabel.text = @"政府";
    }
    if ([typeLabel.text isEqualToString:@"10"]) {
        typeLabel.text = @"社会团体";
    }

    if ([[NSString stringWithFormat:@"%@",[[data objectForKey:@"join"]objectForKey:@"status"]]isEqualToString:@"1"])
    {
        NSString * content = [[data objectForKey:@"join"]objectForKey:@"content"];
        UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70, 20)];
        lable.text = content;
        [lable sizeToFit];
        button2.frame = CGRectMake(ScreenWidth - lable.frame.size.width - 10, 40, lable.frame.size.width , 20);
        [button2 setTitle:[[data objectForKey:@"join"]objectForKey:@"content"] forState:UIControlStateNormal];
        button2.enabled = NO;
    }
    else
    {
        NSString * content = [[data objectForKey:@"join"]objectForKey:@"content"];
        UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70, 20)];
        lable.text = content;
        [lable sizeToFit];
        button2.frame = CGRectMake(ScreenWidth - lable.frame.size.width - 10, 40, lable.frame.size.width , 20);
        [button2 setTitle:[[data objectForKey:@"join"]objectForKey:@"content"] forState:UIControlStateNormal];
        button2.enabled = YES;
    }
    
    descriptionLabel.frame = CGRectMake(60, 75, ScreenWidth - 70, 20);
    descriptionLabel.text = [data objectForKey:@"Intro"];
    [descriptionLabel sizeToFit];
    if (descriptionLabel.frame.size.height < 20)
    {
        line.frame = CGRectMake(0, 75 + 20 + 10, ScreenWidth, 10);
    }
    else
    {
        line.frame = CGRectMake(0, 75 + descriptionLabel.frame.size.height + 10, ScreenWidth, 10);
    }
}

-(void)button1Action
{
    [self.delegate lichengAction];
}

-(void)button2Action
{
    [self.delegate jiaruAction];
}

-(void)button3Action
{
    [self.delegate gushipinpai];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
